package basic;


/**
 * 1. final 修饰的类无法继承
 * 2. final 修饰的方法无法重写
 * 3. final 修饰的字段只能在初始化时进行赋值，之后不能赋值
 */
public class Polymorphic {
    public static void main(String[] args) {
        Student dc = new Doctor("wangjh", 23, 100);
        System.out.println(dc.hello());

        Income [] incomes = {
                new Income(3000),
                new Salary(12000),
                new StateCouncilSpecialAllowance(60000)
        };

        for (Income c:incomes) {
            System.out.println(c.getTax());
        }

    }
}

class Income{

    public Income(double income) {
        this.income = income;
    }

    protected double income;

//    public final double getTax()
    public double getTax(){
        return income * 0.1;
    }
}

class StateCouncilSpecialAllowance extends Income{

    public StateCouncilSpecialAllowance(double income) {
        super(income);
    }

    @Override
    public double getTax(){
        return 0.0;
    }
}

class Salary extends Income{

    public Salary(double income) {
        super(income);
    }

    @Override
    public double getTax(){
        if(income<=5000)
            return 0;

        return 0.2*(income-5000);
    }
}


class Doctor extends Student{

    public Doctor(String name, int age, int score) {
        super(name, age, score);
    }

    @Override
    public String hello(){
        return "Hello " + name;
    }

}
